<?php
function deleteDirectory($dir, $isContentOnly=true)
{
    $os= strtolower(PHP_OS);
    if(strpos($os, "linux")===0)
    {
        if($isContentOnly)
        {
            $dir=rtrim($dir, "/");
            $command="rm -rf {$dir}/*";
        }
        else
        {
            $command="rm -rf {$dir}";
        }
        $success=shell_exec($command);
    }
    else if(strpos($os, "win")===0)
    {
        if($isContentOnly)
        {
            $dir=rtrim($dir, "/\\");
            $command="rmdir {$dir} /s /q";
            $success=shell_exec($command);
            mkdir("logs");
        }
        else
        {
            $command="rmdir {$dir} /s /q";
            $success=shell_exec($command);
        }
    }
    
    if(!is_null($success)) return true;
    
    if (!file_exists($dir)) return true; 
    if (!is_dir($dir) || is_link($dir)) return unlink($dir); 
        foreach (scandir($dir) as $item) { 
            if ($item == '.' || $item == '..') continue; 
            if (!deleteDirectory($dir . "/" . $item)) { 
                chmod($dir . "/" . $item, 0777); 
                if (!deleteDirectory($dir . "/" . $item)) return false; 
            }; 
        } 
        return rmdir($dir); 
}
function isDirectoryEmpty($dir)
{
  if (!is_readable($dir)) return null; 
  if(!file_exists($dir)) return null;
  $handle = opendir($dir);
  while (false !== ($entry = readdir($handle))) {
    if ($entry != "." && $entry != "..") {
      return false;
    }
  }
  return true;
}
function copyDirectory($source,$destination)
{
    if(file_exists($destination))
    {
        return false;
    }
    $success=shell_exec("`cp -r $source $destination`");
    if(!is_null($success))
    {
        return true;
    }
    if ( is_dir( $source ) ) 
    {
        mkdir( $destination );
        $directory = dir( $source );
        while ( FALSE !== ( $readdirectory = $directory->read() ) ) 
        {
            if ( $readdirectory == '.' || $readdirectory == '..' ) 
            {
                continue;
            }
            $PathDir = $source . '/' . $readdirectory; 
            if ( is_dir( $PathDir ) ) 
            {
                copyDirectory( $PathDir, $destination . '/' . $readdirectory );
                continue;
            }
            copy( $PathDir, $destination . '/' . $readdirectory );
        }
        $directory->close();
    }
    else 
    {
        copy( $source, $destination );
    }
    return true;
}
?>